package com.nbsaas.boot.evaluate.rest.convert;

import com.nbsaas.boot.entity.evaluate.Evaluate;
import com.nbsaas.boot.evaluate.api.domain.response.EvaluateResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;
/**
* 评价-实体对象转化成响应对象
*/

public class EvaluateResponseConvert  implements Converter<EvaluateResponse,Evaluate> {

    @Override
    public EvaluateResponse convert(Evaluate source) {
        EvaluateResponse  result = new  EvaluateResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getCatalog()!=null){
                        result.setCatalog(source.getCatalog().getId());
                    }

                    try {
                        if(source.getReplyUser()!=null){
                            result.setReplyUserName(source.getReplyUser().getName());
                        }
                    } catch (Exception ignored) { }


                    try {
                        if(source.getCreator()!=null){
                            result.setCreatorName(source.getCreator().getName());
                        }
                    } catch (Exception ignored) { }


                    try {
                        if(source.getTargetUser()!=null){
                            result.setTargetUserName(source.getTargetUser().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getCreator()!=null){
                        result.setCreator(source.getCreator().getId());
                    }

                    try {
                        if(source.getCatalog()!=null){
                            result.setCatalogName(source.getCatalog().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getEvaluateType()!=null){
                    Map<Integer,String> EvaluateTypeMap=new HashMap<>();
                        EvaluateTypeMap.put(1,"商品评价");
                        EvaluateTypeMap.put(2,"服务评价");
                        EvaluateTypeMap.put(3,"用户评价");
                        EvaluateTypeMap.put(4,"文章评价");
                        EvaluateTypeMap.put(5,"其他评价");
                    String label=  EvaluateTypeMap.get(source.getEvaluateType());
                    result.setEvaluateTypeName(label);
                    }
                    result.setEvaluateType(source.getEvaluateType());
                    if(source.getReplyUser()!=null){
                        result.setReplyUser(source.getReplyUser().getId());
                    }

                    try {
                        if(source.getAuditUser()!=null){
                            result.setAuditUserName(source.getAuditUser().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getAuditUser()!=null){
                        result.setAuditUser(source.getAuditUser().getId());
                    }
                    if(source.getAnonymous()!=null){
                    Map<Integer,String> AnonymousMap=new HashMap<>();
                        AnonymousMap.put(0,"否");
                        AnonymousMap.put(1,"是");
                    String label=  AnonymousMap.get(source.getAnonymous());
                    result.setAnonymousName(label);
                    }
                    result.setAnonymous(source.getAnonymous());
                    if(source.getStoreState()!=null){
                        result.setStoreStateName(String.valueOf(source.getStoreState()));
                    }
                    if(source.getTargetUser()!=null){
                        result.setTargetUser(source.getTargetUser().getId());
                    }
        return result;
    }

}

